#ifndef SERVER_H
#define SERVER_H

#include <netinet/in.h>
#include <sys/time.h>
#include <signal.h>
#include "cJSON.h"
#include "common.h"
#include "log.h"
#include "threadpool.h"
#include "heartbeat.h"

// 客户端连接信息
typedef struct {
    int sockfd;
    struct sockaddr_in addr;
    ConnectionStatus *connStatus;
} ClientInfo;

// 任务数据
typedef struct {
    ClientInfo *client;
    char *data;
    int dataLen;
    unsigned char dataType;
} TaskData;

// 服务器常量定义
#define SERVER_PORT 8080
#define MAX_EVENTS 1024
#define MAX_CLIENT_COUNT 100
#define THREAD_POOL_SIZE 8
#define TASK_QUEUE_SIZE 1000

// 函数声明
void processSiliconWaferData(ClientInfo *client, cJSON *root);
void processProductionData(ClientInfo *client, cJSON *root);
void handleClientData(void *arg);
int setNonBlocking(int fd);
void addClientToEpoll(int epollfd, int sockfd, struct sockaddr_in addr);
void removeClientFromEpoll(int epollfd, ClientInfo *client);
void checkClientStatus();
static void hourlySummaryHandler(int sig);

#endif // SERVER_H